# Maintainer: Martell Malone <Martell Malone at g mail dot com>

_realname=ninja
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.11.1
pkgrel=3
pkgdesc="Ninja is a small build system with a focus on speed (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://ninja-build.org"
license=('spdx:Apache-2.0')
depends=()
options=('strip' 'staticlibs')
makedepends=("re2c" "${MINGW_PACKAGE_PREFIX}-python" "${MINGW_PACKAGE_PREFIX}-cc")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/ninja-build/ninja/archive/v${pkgver}.tar.gz"
        "001-Handle-ERROR_DIRECTORY-when-calling-FindFirstFileExA.patch"::"https://patch-diff.githubusercontent.com/raw/ninja-build/ninja/pull/2160.patch"
        "002-Flush-output-after-each-line.patch"::"https://patch-diff.githubusercontent.com/raw/ninja-build/ninja/pull/2143.patch")
sha256sums=('31747ae633213f1eda3842686f83c2aa1412e0f5691d1c14dbbcc67fe7400cea'
            '855623ffb3199ed5a0a0f750a05f67a9d3285129c1b8e66d045c56bd7d471838'
            'cfa34091d79aebd6722cd2fc3a36f609295414d8e50d428e2104467ef4062163')

prepare() {
  cd "${srcdir}"/ninja-${pkgver}
  # https://github.com/ninja-build/ninja/pull/2160
  patch -p1 -i "${srcdir}"/001-Handle-ERROR_DIRECTORY-when-calling-FindFirstFileExA.patch
  patch -p1 -i "${srcdir}"/002-Flush-output-after-each-line.patch
}

build() {
  mkdir -p "${pkgdir}${MINGW_PREFIX}"/bin
  cd ${srcdir}/ninja-${pkgver}
  ${MINGW_PREFIX}/bin/python3 configure.py --bootstrap --platform mingw
}

package() {
  mkdir -p "${pkgdir}${MINGW_PREFIX}"/bin
  mv "${srcdir}/ninja-${pkgver}/ninja.exe" "${pkgdir}${MINGW_PREFIX}"/bin/
  mkdir -p "${pkgdir}${MINGW_PREFIX}"/lib
  mv "${srcdir}/ninja-${pkgver}/build/libninja.a" "${pkgdir}${MINGW_PREFIX}"/lib/
}
